 {

        var o = require("../UIManager/UISoundManager.js");
        cc.Class({
            extends: cc.Component,
            properties: {
                Sprite_bg: {
                    default: null,
                    type: cc.Sprite
                },
                Sprite_tile: {
                    default: null,
                    type: cc.Sprite
                },
                Sprite_arrow: {
                    default: null,
                    type: cc.Sprite
                },
                tmpTilePrefab: {
                    default: null,
                    type: cc.Prefab
                },
                _tileValue: -1,
                _tileIndex: -1,
                _orgenX: 0,
                _orgenY: 0,
                _isSelected: !1,
                _isInHuanPai: !1,
                _isInPlayAcceptHuanPaiAni: !1,
                _noForChange: [],
                _tmpTile: null,
                _isYellow: !1,
                _selectTimes: 0
            },
            onLoad: function () {
                this.node.getComponent(cc.Button);
                this._touchStartPos = cc.p(0, 0), this._tileValue = -1, this._tileIndex = -1, this._orgenX = 0,
                    this._orgenY = 0, this._isSelected = !1, this._isInHuanPai = !1, this._isInPlayAcceptHuanPaiAni = !1,
                    this._noForChange = [], this._tmpTile = null, this._isYellow = !1, this._selectTimes = 0,
                    this._orgenH = this.node.height, this.registerOnTouch(this.node), this.Sprite_arrow.node.active = !1,
                    Global.notificationCenter.on(Global.eventName.GAME_UPDATE_SELECT_TILE, this._onSelected.bind(this), this),
                    Global.notificationCenter.on(Global.eventName.GAME_ASK_HUANPAI, this._onAskHuanPai.bind(this), this),
                    Global.notificationCenter.on(Global.eventName.GAME_ACCEPT_HUANPAI, this._onAcceptHuanPai.bind(this), this),
                    Global.notificationCenter.on(Global.eventName.GAME_HUANPAI_SELECT_END, this._onHuanPaiSelectEnd.bind(this), this),
                    Global.notificationCenter.on(Global.eventName.GAME_HUANPAI_UNSELECT_ALL, this._onHuanPaiUnSelectAll.bind(this), this),
                    Global.notificationCenter.on(Global.eventName.GAME_UNSELECT_TILE, this._onUnSelectTile.bind(this), this),
                    Global.notificationCenter.on(Global.eventName.GAME_PLAY_ACCEPT_HUANPAI_ANI, this._onAcceptHuanPaiAni.bind(this), this),
                    Global.notificationCenter.on(Global.eventName.GAME_RESET_TILE_YELLOW, this._onResetYellowTile.bind(this), this),
                    Global.notificationCenter.on(Global.eventName.GAME_DES_TILE_TEMTILE, this.desTemTile.bind(this), this),
                    Global.notificationCenter.on(Global.eventName.GAME_SET_TINGGRAY_STANDTILE, this.setTingGrayAction.bind(this), this);
            },
            registerOnTouch: function (e) {
                e.on(cc.Node.EventType.TOUCH_START, this.onTouchStart.bind(this), this), e.on(cc.Node.EventType.TOUCH_MOVE, this.onTouchMove.bind(this), this),
                    e.on(cc.Node.EventType.TOUCH_END, this.onTouchEnd.bind(this), this), e.on(cc.Node.EventType.TOUCH_CANCEL, this.onTouchCancel.bind(this), this);
            },
            start: function () {
            },
            onDestroy: function () {
                Global.notificationCenter.offAll(this);
            },
            update: function (e) {
                if (1 != this.isTmpTile && !this.isScreenShoot) {
                    if (1 == this._isSelected) {
                        if (1 == this._isInPlayAcceptHuanPaiAni) return;
                        this._setTilePosY(this._orgenY + 20);
                    } else this._selectTimes = 0;
                    if (1 == this._isInHuanPai) {
                        var t = Global.tableModel.getSelectHuanPaiColor();
                        if (null != t) {
                            var n = 0, o = -1;
                            for (var i in t) n++, o = Math.floor(t[i].tileValue / 10);
                            n >= Global.tableModel.getChangeTileCount() && o == Math.floor(this._tileValue / 10) && 0 == this._isSelected ? this.setGary() : this.setWhite();
                        } else this.setWhite();
                    } else {
                        var a = Global.tableModel.getPlayerModel(Global.config.SEAT_DOWN);
                        a && (Math.floor(this._tileValue / 10) == a.getAbsenceColor() ? this.setGary() : 1 == this._isYellow ? this.setYellow() : this._tmpTile || this.isTingGray || this.setWhite(),
                        (1 == a.isWin() || 1 == a.isLose() || a.getIsTing()) && (this.setGary(), this.Sprite_arrow && (this.Sprite_arrow.node.active = !1)));
                    }
                    if (this._noForChange.length > 0) for (var r = {}, s = 0; s < this._noForChange.length; s++) {
                        r[Math.floor(this._noForChange[s] / 10)] || Math.floor(this._noForChange[s] / 10) == Math.floor(this._tileValue / 10) && this.setGary();
                    }
                }
            },
            setGary: function () {
                this.Sprite_tile && (this.Sprite_tile.node.color = cc.color(179, 177, 177, 255)),
                this.Sprite_bg && (this.Sprite_bg.node.color = cc.color(179, 177, 177, 255));
            },
            setWhite: function () {
                this.Sprite_tile && (this.Sprite_tile.node.color = cc.color(255, 255, 255, 255)),
                this.Sprite_bg && (this.Sprite_bg.node.color = cc.color(255, 255, 255, 255));
            },
            setYellow: function () {
                this.Sprite_tile && (this.Sprite_tile.node.color = cc.color(205, 216, 75, 255)),
                this.Sprite_bg && (this.Sprite_bg.node.color = cc.color(205, 216, 75, 255));
            },
            updateTile: function (e, t, n) {
                this._isSelected = !1, this._tileValue = e, this._tileIndex = t, this.isTmpTile = !1,
                1 == n && (this.isTmpTile = !0), this._selectTimes = 0;
                var o = "mj_az_01_" + e;
                Global.spriteAtlas.setSpriteFrame(this.Sprite_tile, "Texture/mj_az_tiles", o);
                var i = this.node.getPosition();
                this._orgenX = i.x, this._orgenY = i.y;
                var a = this._getTingAction().length > 0;
                this.Sprite_arrow.node.active = a;
            },
            _getTingAction: function () {
                var e = Global.tableModel.getPlayerModel(Global.config.SEAT_DOWN);
                if (e) for (var t = e.getTingActions(), n = 0; n < t.length; n++) if (this._tileValue == t[n][0]) return t[n][1];
                return [];
            },
            desTemTile: function () {
                this._tmpTile && (this._tmpTile.destroy(), this._tmpTile = null);
            },
            onTouchStart: function () {
                if (1 != this.isTmpTile && !this.isTingGray) {
                    this.desTemTile();
                    var e = {
                        tileIndex: this._tileIndex,
                        tileValue: this._tileValue
                    };
                    Global.notificationCenter.emit(Global.eventName.GAME_UPDATE_SELECT_TILE, e);
                }
            },
            onTouchMove: function (e) {
                if (1 != this.isTmpTile && !this.isTingGray && 1 != this._isInHuanPai && !Global.tableModel.isLockTouchMove() && !Global.tableModel.getIsGameEnd()) {
                    var t = e.getStartLocation(), n = e.getLocation();
                    if (Math.abs(n.x - t.x) >= 10 || Math.abs(n.y - t.y) >= 10) if (null == this._tmpTile) this.node.opacity = 175,
                        this._tmpTile = cc.instantiate(this.tmpTilePrefab), this.node.parent && this.node.parent.addChild(this._tmpTile, 100),
                        this._tmpTile.getComponent("standTileDownController").updateTile(this._tileValue, this._tileIndex, !0),
                        this.setGary();
                    if (this._tmpTile) {
                        var o = this._tmpTile.parent.convertToNodeSpace(n);
                        this._tmpTile.setPosition(cc.p(o.x, o.y + 20));
                    }
                }
            },
            onTouchEnd: function (e) {
                if (1 != this.isTmpTile && !this.isTingGray) {
                    this.resetTmpTile(e);
                    var t = !1, n = !1, i = Global.tableModel.getPlayerModel(Global.config.SEAT_DOWN);
                    i && (t = i.isWin(), n = i.isLose()), Global.userProfile.profile.CLICK_DOUBLE ? this._selectTimes >= 2 && 1 == this._isSelected && 0 == this._isInHuanPai && 0 == t && 0 == n && this.onClickChoose(i) : 1 == this._isSelected && 0 == this._isInHuanPai && 0 == t && 0 == n && (0 == this._getTingAction().length || this._selectTimes >= 2) && this.onClickChoose(i),
                        o.playTileSelectSound();
                }
            },
            onTouchCancel: function (e) {
                1 == this.isTmpTile || this.isTingGray || this.onTouchEnd(e);
            },
            resetTmpTile: function (e) {
                if (1 != this._isInHuanPai && !Global.tableModel.isLockTouchMove() && !Global.tableModel.getIsGameEnd() && (this.node.opacity = 255,
                    this._tmpTile)) {
                    this.desTemTile();
                    var t = e.getStartLocation(), n = e.getLocation();
                    Math.abs(n.x - t.x) >= 40 || Math.abs(n.y - t.y) >= 40 ? this._selectTimes++ : (2 == this._selectTimes && this._selectTimes--,
                    Global.userProfile.profile.CLICK_DOUBLE || (this._isSelected = !1));
                }
            },
            onClickChoose: function (e) {
                if (1 != Global.tableModel.isLockPlayTile()) {
                    var t = {
                        tileIndex: this._tileIndex,
                        tileValue: this._tileValue,
                        seatId: Global.config.SEAT_DOWN
                    };
                    Global.notificationCenter.emit(Global.eventName.GAME_PLAY_A_TILE, t), Global.notificationCenter.emit(Global.eventName.GAME_RESET_TILE_YELLOW),
                        e.setTingActions(null), this.Sprite_arrow.node.active = !1, Global.notificationCenter.emit(Global.eventName.GAME_SHOW_TING_ACTION, null);
                }
            },
            _onSelected: function (e) {
                var t = e.tileIndex;
                if (this._tileIndex == t) if (this._isYellow = !1, cc.info("standTileDownController _onSelected", "************************"),
                1 == this._isInHuanPai) {
                    for (var n = 0; n < this._noForChange.length; n++) if (this._tileValue == this._noForChange[n]) return void cc.info("standTileDownController _onSelected", "换牌中不可换的牌不能被选中");
                    var o = Global.tableModel.getSelectHuanPaiColor();
                    if (null != o) {
                        var i = 0, a = -1;
                        for (var r in o) i++, a = Math.floor(o[r].tileValue / 10);
                        if (i >= Global.tableModel.getChangeTileCount()) {
                            if (a != Math.floor(this._tileValue / 10)) Global.notificationCenter.emit(Global.eventName.GAME_HUANPAI_UNSELECT_ALL, this._tileIndex); else if (0 == this._isSelected) return;
                        } else a != Math.floor(this._tileValue / 10) && Global.notificationCenter.emit(Global.eventName.GAME_HUANPAI_UNSELECT_ALL, this._tileIndex);
                    }
                    this._isSelected = !this._isSelected;
                    var s = {
                        isSelect: this._isSelected,
                        tileIndex: this._tileIndex,
                        tileValue: this._tileValue
                    };
                    Global.notificationCenter.emit(Global.eventName.GAME_HUANPAI_SELECT, s);
                } else Global.notificationCenter.emit(Global.eventName.GAME_SHOW_TING_ACTION, this._getTingAction()),
                    this._isSelected = !0, this._selectTimes++; else 1 != this._isInHuanPai && (this._isSelected = !1,
                    this._setTilePosY(this._orgenY)), e.tileValue == this._tileValue ? this._isYellow = !0 : this._isYellow = !1;
            },
            _onAskHuanPai: function (e) {
                this._isInHuanPai = !0, this._isSelected = !1, this._isYellow = !1, this._setTilePosY(this._orgenY),
                    this._noForChange = e.noChange;
            },
            _onAcceptHuanPai: function () {
                this._isInHuanPai = !1, this._noForChange = [], this._isSelected = !1, this._isYellow = !1,
                    this._setTilePosY(this._orgenY);
            },
            _onHuanPaiSelectEnd: function () {
                this._isInHuanPai = !1, this._noForChange = [], this._isSelected = !1, this._isYellow = !1,
                    this._setTilePosY(this._orgenY);
            },
            _onHuanPaiUnSelectAll: function (e) {
                this._tileIndex != e && (this._isSelected = !1, this._isYellow = !1, this._setTilePosY(this._orgenY),
                    Global.notificationCenter.emit(Global.eventName.GAME_SHOW_TING_ACTION, null));
            },
            _onUnSelectTile: function (e) {
                this._tileIndex == e && (this._isSelected = !1, this._setTilePosY(this._orgenY),
                    Global.notificationCenter.emit(Global.eventName.GAME_SHOW_TING_ACTION, null));
            },
            _onAcceptHuanPaiAni: function (e) {
                this._isInPlayAcceptHuanPaiAni = !0;
                var t = [];
                if (e.indexOf(this._tileIndex) >= 0) {
                    var n = this.node.x, o = this.node.y;
                    t.push(cc.place(cc.p(n, o + 30))), t.push(cc.delayTime(1)), t.push(cc.moveTo(.5, cc.p(n, o)));
                }
                var i = this;
                t.length > 0 && this.node.runAction(cc.sequence(t)), tywx.Timer.setTimer(this, function () {
                    i._isInPlayAcceptHuanPaiAni = !1;
                }, 2);
            },
            _onResetYellowTile: function (e) {
                this._isYellow = !1;
            },
            _setTilePosY: function (e) {
                this.action && this.action.isDone() && (this.node.y = e, e == this._orgenY + 20 ? this.node.height = this._orgenH + 40 : this.node.height = this._orgenH);
            },
            setAction: function (e) {
                this.action = e;
            },
            setHuanPaiStandTile: function () {
                this._setTilePosY(this._orgenY + 20);
            },
            setInScreenShoot: function () {
                this.isScreenShoot = !0, this.setWhite();
            },
            setTingGrayAction: function (e) {
                e ? this.Sprite_arrow.node.active || (this._onResetYellowTile(), this.isTingGray = !0,
                    this.setGary()) : this.reset();
            },
            reset: function () {
                this.isTingGray = !1;
            }
        })
    }